package com.example.myapplication22.OnclickImplements;

import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication22.Register;

public class AiHao extends AppCompatActivity implements View.OnClickListener{
    private String[] items=new String[]{"篮球","足球","羽毛球"};
    private boolean[] booleans=new boolean[]{true,false,false};
    AlertDialog dialog=null;

    @Override
    public void onClick(View view) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle("请添加兴趣爱好")
                .setMultiChoiceItems(items, booleans, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                        //设置是否选中
                        booleans[i]=b;
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        StringBuilder stringBuilder = new StringBuilder();
                        //循环
                        for (int a=0;a<booleans.length;a++){
                            if (booleans[a]){
                                stringBuilder.append(items[a]+" ");
                            }
                        }
                        //Toast显示
                     // Toast.makeText(this,stringBuilder,Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
                    }
                });
        dialog=builder.create();
        dialog.show();

    }
}
